﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////

#pragma execution_character_set("utf-8")

// qt headers
#include <QPushButton>
#include <QHBoxLayout>

// custom headers
#include "SearchTextBox.h"
#include "GbmpNew.h"
#include "DebugMessage.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h" 

namespace gmepgcs
{
    SearchTextBox::SearchTextBox(QString &placeHolderText, QWidget *parent) : QLineEdit(parent)
    {
        setStyleSheet(
            "font-family:\"Microsoft YaHei\";"
            "font-size:12px;");
        setPlaceholderText(placeHolderText);
        setFixedWidth(240);
        setFixedHeight(24);
        setTextMargins(0, 1, 24, 1);

        // layout
        QHBoxLayout* pHLayout = NEW_AS_QT (QHBoxLayout);
        DBG_WARN_AND_RETURN_VOID_UNLESS(pHLayout, L"pHLayout为空", L"GMEP", L"2024-01-30");
        setLayout(pHLayout);
        pHLayout->setContentsMargins(0, 0, 0, 0);
        pHLayout->addStretch();

        //Search button
        auto pBtnSearch = NEW_AS_QT(QPushButton,this);
        DBG_WARN_AND_RETURN_VOID_UNLESS(pBtnSearch, L"pBtnSearch为空", L"GMEP", L"2024-01-30");
        pBtnSearch->setObjectName("SearchButtonInSearchLineEdit");
        pHLayout->addWidget(pBtnSearch);
        pBtnSearch->setFixedHeight(24);
        pBtnSearch->setFixedWidth(24);
        pBtnSearch->setStyleSheet("color: rgba(136, 146, 160, 1)");
        pBtnSearch->setFlat(true);
        pBtnSearch->setIcon(QIcon(":/images/search_icon2.png"));
        pBtnSearch->setCursor(QCursor(Qt::PointingHandCursor));
        connect(pBtnSearch, &QPushButton::clicked, this, &SearchTextBox::Searched);
    }

    SearchTextBox::~SearchTextBox()
    {
    }

}